var express = require("express");
var mustacheExpress = require("mustache-express");

var app = express();

var items = {
    title : "Hello Express.",
    list : [
        { name : "Hugo Hoo", age : 20 },
        { name : "Ooho", age : 21 },
        { name : "Fucker", age : 22 }
    ]
}

var profile = {
    users : [
        { name : "hugohoo0", age : 20 },
        { name : "hugohoo1", age : 21 },
        { name : "hugohoo2", age : 22 },
        { name : "hugohoo3", age : 23 },
        { name : "hugohoo4", age : 24 },
        { name : "hugohoo5", age : 25 },
        { name : "hugohoo6", age : 26 },
        { name : "hugohoo7", age : 27 },
        { name : "hugohoo8", age : 28 },
    ]
}

// 注册引擎
app.engine(".html", mustacheExpress());

// 设置模板文件的目录
app.set("views", __dirname + "/views");
// 设置模板引擎
app.set("view engine", "html");

// 托管静态文件，可通过浏览器直接访问，HTML中也可以通过link, script引入（因为每个link和script的引入都会向服务器请求资源）
app.use(express.static("./public"));

app.get("/", function(req, res){
    // res.render("index", items);
    res.sendFile(__dirname + "/views/index.html");
});

app.get("/profile/users", function(req, res){
    console.log("/profile/users request recieved.");
    res.send(profile);
});

app.listen(3000, function(){
    console.log("server listening at http://localhost:3000");
});